package com.alinesno.cloud.monitor.agent.collect;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.druid.pool.DruidDataSource;
import com.alinesno.cloud.compoment.kafka.KafkaProducer;
import com.alinesno.cloud.monitor.agent.tool.SpringContextUtil;

/**
 * 数据库源配置
 * @author WeiXiaoJin
 * @since 2020年1月25日 下午19:45:08
 */
public class DatasourceConfig implements InitializingBean {

	@Autowired
	protected KafkaProducer kafkaProducer; 
	
	@Override
	public void afterPropertiesSet() throws Exception {
		DruidDataSource d = SpringContextUtil.getBean(DruidDataSource.class) ; 
		if(d != null) {
			d.setStatLogger(new WatcherSQLStatLogger(kafkaProducer));
		}
	}

//	@Bean("druidStatInterceptor")
//	public DruidStatInterceptor druidStatInterceptor() {
//		return new DruidStatInterceptor() ; 
//	}
//	
//	@Bean("druidStatPointcut")
//	public JdkRegexpMethodPointcut jdkRegexpMethodPointcut() {
//		JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut() ; 
//		pointcut.setPatterns(new String[] {
//				"com.alinesno.coud..*.*.service.*" ,
//				"com.alinesno.coud..*.*.repository.*" 
//		});
//		return pointcut ; 
//	}
	
}
